<?php
defined('JPATH_BASE') or die;

jimport('joomla.html.html');
jimport('joomla.form.formfield');

class JFormFieldCheckboxesfood extends JFormField
{
   public $type = 'Checkboxesfood';
   protected function getInput()
   {
      $db =& JFactory::getDBO();
      $query = "SELECT * FROM #__categories where extension = 'com_foodcats' and published=1 order by id ASC";
      $db->setQuery($query);
      $categories = $db->loadObjectList();
      $var_list ='';
	  
	  $skills = @(json_decode($this->value));
	 
      foreach($categories as $category){
		  $in  = false;
		  for($j=0;$j<sizeof($skills);$j++) 
		  {
			  if($skills[$j] == $category->id) $in = true;
		  }
		  if($in == true) 
		  {
         	  $var_list.= '<li><input  checked="checked" name="'.$this->name.'[]" type="checkbox" value="'.$category->id.'"><label for="jform_category_id'.$category->id.'">'.$category->title.'</label></li>';
		  } else {
			  $var_list.= '<li><input name="'.$this->name.'[]" type="checkbox" value="'.$category->id.'"><label for="jform_category_id'.$category->id.'">'.$category->title.'</label></li>';
	  	  }
      }
      return '<fieldset id="jform_category_id" class="checkboxes"><ul>'.$var_list.'</ul></fieldset>';
   }
}
?> 